package com.yanqu.road.server.logic.thread.platform;

import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.thirdparty.PlatformMgr;
import com.yanqu.road.server.manger.union.UnionMgr;
import com.yanqu.road.server.pb.UnionPb;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.executor.GeneralTask;

public class UnionModifyTask extends GeneralTask {
    private GamePlayer player;
    private int type;         //0：联盟名称； 1：微信号； 2：qq号； 3：对外公告； 4：对内公告
    private String content;

    public UnionModifyTask(GamePlayer player, int type, String content) {
        super();
        this.player = player;
        this.type = type;
        this.content = content;
    }

    @Override
    public void doRun() {
        //修改昵称
        int ret = PlatformMgr.unionModify(player, type, content);

        //响应
        UnionProto.UnionModifyRespMsg.Builder respMsg = UnionProto.UnionModifyRespMsg.newBuilder();
        respMsg.setRet(ret);
        if (ret == 0) {
            UnionInfo unionInfo = UnionMgr.getUnionInfo(player.getUserInfo().getUnionUid());
            UnionProto.UnionTempMsg.Builder unionMsg = UnionPb.parseUnionTempMsg(unionInfo);
            if (null != unionMsg) {
                respMsg.setUnion(unionMsg);
            }
        }
        player.sendPacket(Protocol.U_UNION_MODIFY, respMsg);
    }
}
